#include <iostream>
#include <string>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <unistd.h>
#include "Shm.hpp"
#include "Fifo.hpp"

using namespace std;

#define GET_KEY_PATH "/home/ubuntu/zzz/mycode/pipe/shm"
#define PROJ_ID 0x66
#define SIZE 1024
int main()
{
    Shm shm;
    // 得到 key 和 shmid
    key_t key = shm.GetShmKey(GET_KEY_PATH, PROJ_ID);
    int shmid = shm.GetShm(key, SIZE);

    // 将 key 和 shmid 设置进对象中
    shm.SetShm(key, shmid);
    // 挂接
    char *buf = (char *)shm.ShmAttach();

    // 利用命名管道实现同步
    Sync sync;
    sync.Openwrite(NAMEED_PIPE_Path);

    for (int i = 0; i < 5; i++)
    {
        sleep(1);
        buf[i] = 'A' + i;
        cout << "send message!" << endl;
        sync.SendSig();
    }
    shm.ShmDetach();

    return 0;
}